﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
#pragma warning disable 436

namespace Code
{
    public class HoaDonController
    {
        HoaDonDataAccess _dataAccess;

        public HoaDonController()
        {
            _dataAccess = new HoaDonDataAccess();
        }

        public DataTable GetListSanPham(String strID)
        {
            return _dataAccess.GetListSanPham(strID);
        }

        public bool DeleteHoaDon(String strID)
        { 
            return _dataAccess.DeleteHoaDon(strID);
        }

        public bool UpdateHoaDon(HoaDonInfo hd)
        {
            return _dataAccess.UpdateHoaDon(hd);
        }

        public HoaDonInfo GetHoaDonDaXacNhan(String strID)
        {
            DataTable dt = _dataAccess.GetHoaDonDaXacNhan(strID);
            HoaDonInfo hd = new HoaDonInfo();
            if ((dt != null) && (dt.Rows.Count > 0))
            {
                hd.NguoiDatHang = dt.Rows[0]["NguoiDatHang"].ToString();
                hd.NgayDatHang = dt.Rows[0]["NgayDatHang"].ToString();
                hd.PhuongThucThanhToan = dt.Rows[0]["PhuongThucThanhToan"].ToString();
                hd.PhuongThucGiaoHang = dt.Rows[0]["PhuongThucGiaoHang"].ToString();
                hd.TongTien = dt.Rows[0]["TongTien"].ToString();
                hd.NguoiXacNhan = dt.Rows[0]["NguoiXacNhan"].ToString();
                hd.NgayXacNhan = dt.Rows[0]["NgayXacNhan"].ToString();
                hd.GhiChu = dt.Rows[0]["GhiChu"].ToString();
                hd.TenNguoiNhan = dt.Rows[0]["TenNguoiNhan"].ToString();
                hd.SoDienThoai = dt.Rows[0]["SoDienThoai"].ToString();
                hd.DiaChi = dt.Rows[0]["DiaChi"].ToString();
                return hd;
            }
            else
                return null;
        }

        public HoaDonInfo GetHoaDonChuaXacNhan(String strID)
        {
            DataTable dt = _dataAccess.GetHoaDonChuaXacNhan(strID);
            HoaDonInfo hd = new HoaDonInfo();
            if ((dt != null) && (dt.Rows.Count > 0))
            {
                hd.NguoiDatHang = dt.Rows[0]["NguoiDatHang"].ToString();
                hd.NgayDatHang = dt.Rows[0]["NgayDatHang"].ToString();
                hd.PhuongThucThanhToan = dt.Rows[0]["PhuongThucThanhToan"].ToString();
                hd.PhuongThucGiaoHang = dt.Rows[0]["PhuongThucGiaoHang"].ToString();
                hd.TongTien = dt.Rows[0]["TongTien"].ToString();
                hd.NguoiXacNhan = "Chưa xác nhận";
                hd.NgayXacNhan = "";
                hd.GhiChu = dt.Rows[0]["GhiChu"].ToString();
                hd.TenNguoiNhan = dt.Rows[0]["TenNguoiNhan"].ToString();
                hd.SoDienThoai = dt.Rows[0]["SoDienThoai"].ToString();
                hd.DiaChi = dt.Rows[0]["DiaChi"].ToString();
                return hd;
            }
            else
                return null;
        }

        public List<PhuongThucThanhToan> GetListPhuongThucThanhToan()
        {
            DataTable dt = _dataAccess.GetListPhuongThucThanhToan();
            List<PhuongThucThanhToan> listPTTT = new List<PhuongThucThanhToan>();

            if ((dt != null) && (dt.Rows.Count > 0))
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    PhuongThucThanhToan pttt = new PhuongThucThanhToan();
                    pttt.ID = Convert.ToInt32(dt.Rows[i][0].ToString());
                    pttt.TenPhuongThuc = dt.Rows[i][1].ToString();
                    listPTTT.Add(pttt);
                }
                return listPTTT;
            }
            else
                return null;
        }

        public List<PhuongThucGiaoHang> GetListPhuongThucGiaoHang()
        {
            DataTable dt = _dataAccess.GetListPhuongThucGiaoHang();
            List<PhuongThucGiaoHang> listPTGH = new List<PhuongThucGiaoHang>();

            if ((dt != null) && (dt.Rows.Count > 0))
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    PhuongThucGiaoHang pttt = new PhuongThucGiaoHang();
                    pttt.ID = Convert.ToInt32(dt.Rows[i][0].ToString());
                    pttt.TenPhuongThuc = dt.Rows[i][1].ToString();
                    listPTGH.Add(pttt);
                }
                return listPTGH;
            }
            else
                return null;
        }

        public List<NhanVien> GetListNhanVien()
        {
            DataTable dt = _dataAccess.GetListNhanVien();
            List<NhanVien> listNV = new List<NhanVien>();

            if ((dt != null) && (dt.Rows.Count > 0))
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    NhanVien nv = new NhanVien();
                    nv.ID = Convert.ToInt32(dt.Rows[i][0].ToString());
                    nv.TenDangNhap = dt.Rows[i][1].ToString();
                    listNV.Add(nv);
                }
                return listNV;
            }
            else
                return null;
        }
    }
}
